<?php


class m_news extends M {



	function __init__ () {
	
		$this->db->settable("www_news")->init();
	
	}

	function news_add() {

		$_POST["ctime"] = time();
		$_POST["etime"] = time();

		$_POST["content"] = $this->news_baidu($_POST["content"]);

		if($this->db->insert($_POST,0)) {
			

				$this->php->redirect("?a=news_add",3,"添加新闻成功");
				exit();
		}else {
		
			echo "insert error";
		
		}

	}

	function news_list() {

		//加载分页类
		include 'Pagination/Pagination.php';
		include 'Pagination/PaginationConfig.php';
		$page = !empty($_GET['p']) ? (int)$_GET['p'] : 1;

		$nu = $this->db->total();
		$pagesize=30;


		//初始化分页对象
		$pagination = new LtPagination;
		$pagination->conf->total_rows = $nu; //总数
		$pagination->conf->cur_page = $page; //当前页
		$pagination->conf->page_size = $pagesize; //每页显示数
		//$pagination->conf->base_url = 'newslist-'.$id.'-:page'.'.pl'; // :page会自动被替换掉
		$pagination->conf->base_url = "?a=news_list&p=:page";
		$pagination->init();
		$pageurl = $pagination->pages;


		//分页起始参数
		$climit=($page-1)*$pagesize;
		$list=$this->db->order("id desc")->limit($climit,$pagesize)->select();

		$this->view->assign("pageurl",$pageurl);
		$this->view->assign("list",$list);

	}

	function news_find($id) {
		$vo = $this->db->where("id = ".$id)->find();
		return $vo;
	}

	function news_update($id) {
		if($this->db->where("id =".$id)->update($_POST,0)) {
			$this->php->redirect("?a=news_list",3,"修改成功");
		}else {
			echo "news update error";
		}
	}

	/*
		为原创处理，关键词替换
	*/
	function news_baidu($html) {

		$kv = array(
			"现代"=>"当代",
			"离职" => "辞职",
			"职场" => "工作",
			"，" => ",",
			"。" => ".",
			"一" => "1",
			"二" => "2",
			"三" => "3",
			"四" => "4",
			"五" => "5",

		);


		foreach($kv as $k => $v) {
			$html = str_replace($k,$v,$html);
		}

		return $html;
	}










}